package com.li.controller;

import com.li.pojo.Course1;

import com.li.service.Course1Service;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Collection;

@Controller
public class Course1Controller {

    @Resource
    Course1Service service;

    @RequestMapping("/courses1")
    public String list(Model model){
        Collection<Course1> course1s=service.allCourse1();
        model.addAttribute("course1s",course1s);
        return "course1/list";
    }
    @GetMapping(value = "/tocourse1")
    public String tocourse1(Model model){

        return "course1/add";
    }
    @RequestMapping(value = "/course1/add")
    //@ResponseBody
    public String addCourse1(Course1 course1){
        System.out.println("1");
        if(service.addCourse1(course1))return "redirect:/courses1";
        return "教工号重复，添加失败";
    }
    @RequestMapping(value = "/course1/query")
    public String queryCourse1(){
        return "";
    }

    @GetMapping("/course1/{cnumber}")
    public String toupdateCourse1(
            @PathVariable("cnumber")String cnumber, Model model){

        Course1 course1=new Course1(cnumber);
        course1=service.queryCourse1(course1);
        model.addAttribute("cou",course1);
        return "course1/update";
    }
    @RequestMapping(value = "/course1/update")
    public String updateCourse1(Course1 course1){
        System.out.println("1");
        service.updateCourse1(course1);
        return "redirect:/courses1";
    }
    @RequestMapping(value = "/delecourse1/{cnumber}")
    public String deleteCourse1(@PathVariable("cnumber")String cnumber){
        Course1 course1=new Course1(cnumber);
        service.deleteCourse1(course1);
        return "redirect:/courses1";
    }
}
